# coding:utf-8
"""
Created on 2018.07.26
@author: 顾晨哲
"""

import config
from common import tools

mdb = config.mdb

class SalonRelation(object):
    def __init__(self, rid=""):
        self._rid = tools.id2objectid(rid)

    # 获取关系 
    def get_detail(self):
        return mdb.salon_relation.find_one({'_id': self._rid})

    # 创建关系
    def create(self, sid, myid):
        db_salon = mdb.salon_relation.find({"sid": sid, "myid": myid, "status": {"$in": [0, 1]}})
        if db_salon:
            return False

        rel = {
            "sid": sid,  # 发廊id
            "myid": myid,  # 发型师id
            "join_time": "",  # 审核通过加入时间
            "unbind_time": "",  # 解绑时间
            "status": 0,  # 状态 0-发廊审核中 1-发廊审核通过已绑定 2-拒绝 3-已解除绑定
            "cdate": tools.datetime_utc(),
            "udate": tools.datetime_utc()
        }
        mdb.salon_relation.insert_one(rel)
        return True

    # 更新信息
    def update_info(self, data):
        mdb.salon_relation.update({'_id': self._rid}, {'$set': data})
